package com.sf.fy.uav.applet.utils;

import com.sf.fy.uav.task.service.impl.AirStationServiceImpl;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.http.HttpRequest;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @author 01430312
 */
@Aspect
@Component
public class MyAspect {
    private final static Logger logger = LoggerFactory.getLogger(MyAspect.class);

    /**
     * 定义前置通知方法
     */
    @Before("execution(* com.sf.fy.uav.*.service.*.*(..))")
    public void beforeAdvice() {
        System.out.println("执行前置通知");
        ServletRequestAttributes requestAttributes = ServletRequestAttributes.class.cast(RequestContextHolder.getRequestAttributes());
        if (!ObjectUtils.isEmpty(requestAttributes)) {
            // 从请求上下文里获取Request对象
            HttpServletRequest req = requestAttributes.getRequest();
            String queryString = req.getQueryString();
            if (!ObjectUtils.isEmpty(queryString)) {
                logger.info(queryString);
            }

            StringBuffer requestURL = req.getRequestURL();
            logger.info(requestURL.toString());
        }


    }

}